package com.greenhouse.business.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.greenhouse.business.domain.BizGroupAlarm;
import com.greenhouse.business.service.IBizGroupAlarmService;
import com.greenhouse.common.annotation.Log;
import com.greenhouse.common.core.controller.BaseController;
import com.greenhouse.common.core.domain.AjaxResult;
import com.greenhouse.common.core.page.TableDataInfo;
import com.greenhouse.common.enums.BusinessType;
import com.greenhouse.common.utils.poi.ExcelUtil;

/**
 * group_alarmController
 * 
 * @author greenhouse
 * @date 2021-05-09
 */
@RestController
@RequestMapping("/group/alarm")
public class BizGroupAlarmController extends BaseController {
	@Autowired
	private IBizGroupAlarmService bizGroupAlarmService;

	/**
	 * 查询group_alarm列表
	 */
	@PreAuthorize("@ss.hasPermi('大棚设备报警:alarm:list')")
	@GetMapping("/list")
	public TableDataInfo list(BizGroupAlarm bizGroupAlarm) {
		startPage();
		List<BizGroupAlarm> list = bizGroupAlarmService.selectBizGroupAlarmList(bizGroupAlarm);
		return getDataTable(list);
	}

	@GetMapping("/listAlarmByGroupId/{groupId}")
	public TableDataInfo listAlarmByGroupId(@PathVariable("groupId") Long groupId) {
		startPage();
		BizGroupAlarm bizGroupAlarm = new BizGroupAlarm();
		bizGroupAlarm.setGroupId(groupId);
		List<BizGroupAlarm> list = bizGroupAlarmService.selectBizGroupAlarmList(bizGroupAlarm);
		return getDataTable(list);
	}

	/**
	 * 导出group_alarm列表
	 */
	@PreAuthorize("@ss.hasPermi('大棚设备报警:alarm:export')")
	@Log(title = "group_alarm", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(BizGroupAlarm bizGroupAlarm) {
		List<BizGroupAlarm> list = bizGroupAlarmService.selectBizGroupAlarmList(bizGroupAlarm);
		ExcelUtil<BizGroupAlarm> util = new ExcelUtil<BizGroupAlarm>(BizGroupAlarm.class);
		return util.exportExcel(list, "alarm");
	}

	/**
	 * 获取group_alarm详细信息
	 */
	@PreAuthorize("@ss.hasPermi('大棚设备报警:alarm:query')")
	@GetMapping(value = "/{alarmId}")
	public AjaxResult getInfo(@PathVariable("alarmId") Long alarmId) {
		return AjaxResult.success(bizGroupAlarmService.selectBizGroupAlarmById(alarmId));
	}

	/**
	 * 新增group_alarm
	 */
	@PreAuthorize("@ss.hasPermi('大棚设备报警:alarm:add')")
	@Log(title = "group_alarm", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody BizGroupAlarm bizGroupAlarm) {
		return toAjax(bizGroupAlarmService.insertBizGroupAlarm(bizGroupAlarm));
	}

	/**
	 * 修改group_alarm
	 */
	@PreAuthorize("@ss.hasPermi('大棚设备报警:alarm:edit')")
	@Log(title = "group_alarm", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody BizGroupAlarm bizGroupAlarm) {
		return toAjax(bizGroupAlarmService.updateBizGroupAlarm(bizGroupAlarm));
	}

	/**
	 * 删除group_alarm
	 */
	@PreAuthorize("@ss.hasPermi('大棚设备报警:alarm:remove')")
	@Log(title = "group_alarm", businessType = BusinessType.DELETE)
	@DeleteMapping("/{alarmIds}")
	public AjaxResult remove(@PathVariable Long[] alarmIds) {
		return toAjax(bizGroupAlarmService.deleteBizGroupAlarmByIds(alarmIds));
	}
}
